home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / keyb / fastbf26.zip / FASTBF26.ASM next >
Assembly Source File  |  1989-08-14  |  44KB  |  1,648 lines

  1.     PAGE    ,132
  2.  
  3. ;       FASTBUFF.ASM - Keyboard buffer resident utility.
  4.  
  5. ;             Version 2.6
  6.  
  7. ;            by: David Steiner
  8. ;            [D.STEINER] on GEnie
  9. ;            2035 J Apt. 6
  10. ;            Lincoln, NE   68510
  11. ;            (402) 475-0601
  12.  
  13. ;    This is a fairly big update from version 1.0.  FASTBUFF now
  14. ;    handles Alt-keypad character entries correctly, plus fixes
  15. ;    these characters since many IBM clones generate incorrectly.
  16.  
  17. ;    The way characters are restored to the system has been updated
  18. ;    also.  We no longer hook the Keyboard I/O interrupt, instead we
  19. ;    continuously keep the BIOS buffer full by filling it every time
  20. ;    the system timer clicks (Interrupt 1C).
  21. ;    This was done as an allowance for programs that bypass the BIOS
  22. ;    when doing character I/O.  It has the added benefit of allowing
  23. ;    FASTBUFF to be active when installed after other utilities that
  24. ;    hook into interrupt 16.
  25.  
  26. ;    The only software compatibility problems that should arise will
  27. ;    be with other programs that hook the Keystroke interrupt and attempt
  28. ;    to insert characters directly into the BIOS keyboard buffer.
  29. ;       "Key-fake" utilities are an example of such programs.    If you
  30. ;    need to use such a program, it is best to deactivate FASTBUFF first.
  31.  
  32. ;v2.6    Toad Hall, 14 Aug 89
  33. ; -    Bug:  When setting many many cmdline switches (example:
  34. ;        FASTBUFF /V0 /B50 /D9 /S
  35. ;    program reports an error with the last switch/parameter.
  36. ;    Checking out cmdline parsing.
  37. ;    Thanks to Keith Petersen's son for reporting this one!
  38. ; -    Bug in cmdline parsing .. we were not correctly AsciiZing the last parm
  39. ;    (skipped an essential loop!).
  40. ; -    Bug in SetDelay:  checking for illegal high value, the 'jz' branch
  41. ;    should've been 'jnz' .. dumb!
  42. ; -    Removing old 'v2.5' comments.
  43.  
  44. ;v2.5    Toad Hall tweak, 1 May 89
  45. ; -    Removing old "v2.n" comments.
  46. ; -    Changed default screen blanking to 6 minutes.
  47. ; -    Using one beep for ACK or on, two beeps for off.
  48. ;    Rewrote the beep code because of an irritating click and delay
  49. ;    on my system.  Sound is now 8253 timer-driven.
  50. ;    Frequency is arbitrary.
  51. ;    Could be this will break any programs doing simultaneous music/sound
  52. ;    (or other timer-driven activities) and keyboard activity ..
  53. ;    but then we don't beep THAT often!
  54.  
  55. ;v2.4    Toad Hall Debug, Tweak, 2 Apr 89
  56. ; -    Added new command line parameter processing.
  57. ; -    Fixed possible bug in '/v' video blanking delay.
  58. ; -    Tightened up, debugged GetNum procedure for cmdline numeric values.
  59. ; -    Adding explanatory error msgs for faulty command line parameters.
  60. ; -    Left the rest alone for now.
  61. ; -    Per Keith Petersen's suggestion, adding forced screen blanking
  62. ;    ([5][End]).
  63. ; -    Also added a screen blanking toggle ([5][HOME].
  64. ;    Overrides the commandline '/V' or '-V0' (whichever) (if any).
  65. ; -    Tightened up Command key processing a little (sharing common code).
  66. ; -    Added a real short beep to acknowledge [5] commands.
  67. ; -    Single short beep means "ON", extra-long beep means "OFF".
  68. ; -    Considering a pop-up window with function-key or cursor-key
  69. ;    variable settings (rather than the somewhat cryptic [5][whatever]
  70. ;    combos we're using now).  That would add a lot of code, though,
  71. ;    plus storage space for user's screen, etc.  Maybe later.
  72. ; -    No problem with switching from Int 1CH to Int 8 .. I was tempted
  73. ;    to do the same myself, but wanted to keep this "well-behaved".
  74. ; -    Removed code commented out by v2.2, v2.3.
  75.  
  76. ;v2.3    Dave, March 15, 1989
  77. ; -    Changed timer interrupt vector from 1C to 8.
  78. ;    This fixes problems with programs that incorrectly hook the
  79. ;    software timer interrupt (1C).  IBM BASIC is one such program.
  80.  
  81. ;v2.2    Toad Hall Tweak, 2 Mar 89
  82. ; -    Keith Petersen detected DSZ serial port errors when FASTBUFF was
  83. ;    installed and DSZ was running at VERY high (19200 baud) rates.
  84. ;    Suspect we're grabbing interrupts too often or too long.
  85. ;    Tweaking to reduce CLI periods and ANY other delays.
  86. ; -    Removed a bunch of v2.0 code I'd commented out in v2.1
  87. ;    (since v2.1 seems to be working all right).
  88.  
  89. ;v2.1    Toad Hall Tweak, 23 Feb 89
  90. ; -    General tightening
  91. ; -    Much more use of AX vs. other regs
  92. ; -    Described a Page40 segment to permit faster BIOS variable
  93. ;    addressing.
  94. ; -    Now using DS: instead of ES: to address BIOS variables.
  95. ; -    FATAL error when new interrupt svcs call or jump to the old
  96. ;    interrupt vectors!  Author didn't address the saved vector
  97. ;    (oldint9, etc.) as CS:.
  98. ; -    Tightened up installation procedure:
  99. ;    - Uses runtime variables rather than installation variables.
  100. ;    - If error, terminates with proper Svc 4CH, Int 21H.
  101. ;    - Now freeing environment variable before going TSR
  102. ;    - Rounding up TSR program/data size to nearest paragraph
  103. ;      before going TSR.
  104. ; -    Reduced .COM file about 1Kb.  Runtime memory requirements:
  105. ;    - v2.0  1504 bytes, 2 blocks
  106. ;    - v2.1  1296 bytes, 1 block
  107. ;    .. not too shabby.
  108.  
  109. ;    Kudos to the author .. nice logic.
  110.  
  111. ;    David Kirschbaum
  112. ;    Toad Hall
  113. ;    kirsch@braggvax.ARPA
  114.  
  115.  
  116. ;------ EQUATES
  117.  
  118. CR    equ    0DH
  119. LF    equ    0AH
  120. TIMER    equ    40H        ;timer chip
  121. PORT_B    equ    61H        ;8253 port B
  122. HIFREQ    equ    300        ;high freq for on
  123. LOFREQ    EQU    900    ;200    ;low freq for off
  124. ERRFREQ    equ    350        ;keyboard overrun beep
  125.  
  126.  
  127. ;------ BIOS buffer & otherstuff equates
  128.  
  129. Page40  segment at    40H
  130.     org    10H
  131. biosequipflags  dw    ?        ;410H BIOS equipment word address
  132.  
  133.     org    17H
  134. ;------ BIOS shift status byte 1 & masks for action key combinations
  135.  
  136. biosshflags    db    ?        ;417H First BIOS shift status byte
  137.         db    ?
  138.  CLRMASK    equ    05H        ; Clear buffer key mask
  139.  
  140. biosaltbuff    db    ?        ;419H Storage for Alt-keypad entries
  141. bioshead    dw    ?        ;41AH BIOS keyboard buffer head
  142. biostail    dw    ?        ;41CH  ""  tail
  143. biosbuffer    db    ?        ;41EH BIOS keyboard buffer start
  144.  
  145.         org    3EH
  146. biosendbuff    label    byte        ;43EH end
  147.  
  148.         org    65H
  149. bioscrtmodeset  db    ?        ;465H
  150. biospalette    db    ?        ;466H
  151.  EQUIPMASK    equ    0010H
  152.  PALETTEMASK    equ    0FH
  153.  
  154.         org    71H
  155. ;------ BIOS break detection byte
  156. biosbreak    db    ?        ;471H Bit 7 of this byte indicates
  157.  BREAKMASK    equ    80H        ;  ctrl-break was pressed
  158.  
  159. Page40  ENDS
  160.  
  161.  
  162. KBINPORT    equ    60H        ; Keyboard data port
  163. ;KBCTRLPORT    equ    61H        ; Keyboard control port
  164. ALTSHIFT    equ    38H        ; ALT key scan code
  165.  
  166. ;------ FASTBUFF control key scan codes
  167.  
  168. FBCTRLKEY    equ    4CH        ; Scan code for "5" on keypad
  169.  
  170. FBONKEY        equ    52H        ; Code for INS key
  171. FBOFFKEY    equ    53H        ; Code for DEL key
  172. FBFAST        equ    4EH        ; Code for keypad "+"
  173. FASTREP        equ    2        ; Chars per click for fast rate
  174. FBSLOW        equ    4AH        ; Code for keypad "-"
  175. SLOWREP        equ    1        ; Chars per click for slow rate
  176. FBENDKEY    equ    4FH        ; Code for END key
  177. FBHOMEKEY    equ    47H        ; Code for HOME key
  178.  
  179. ;------ Masks for altering bits in our status byte.
  180.  
  181. FBMASK        equ    01H        ; Masks for FASTBUFF toggle
  182. REPMASK        equ    02H        ; On when we need to repeat a character
  183. SCRMASK        equ    04H        ; On while screen is active
  184. CTRLMASK    equ    08H        ; On when [5] is being held down
  185. OLDINT9MASK    equ    10H        ; On when processing char with old int9
  186. VIDMASK        equ    20H        ; Video blanking active?
  187. BLANKMASK    equ    40H        ; Forced video blanking?
  188.  
  189.  
  190. CSEG    segment public para 'CODE'
  191.     ASSUME  CS:CSEG, DS:CSEG
  192.  
  193.     org    2CH
  194. env_adr dw    ?            ;environment segment
  195.  
  196.     org    80H
  197. nchar    db    ?            ;PSP cmdline char count
  198. params    db    ?            ;PSP cmdline chars
  199.  
  200.     org    100H
  201.  
  202. Start:
  203.     jmp    Initialize
  204.  
  205.  
  206. ;------ Old vector storage area
  207.  
  208. oldint9        dw    0,0
  209. oldint10    dw    0,0
  210. oldint8        dw    0,0
  211.  
  212. ;--------------------------------------------------------------------------
  213. ;Resident data area
  214. ;--------------------------------------------------------------------------
  215.  
  216. lastchar    dw    0FFFFH        ; Last character typed, undef at start
  217. repcount    db    ?        ; # ticks till next repeat
  218. repchars    db    2        ; Default # chars to repeat
  219.                     ; per click
  220. ;    Keith Petersen suggested increasing this start delay a little
  221. ;    (because of repeated Return keys, fast cursor keys, etc.).
  222. ;    Changing from the original 5 to 7 ticks delay.
  223.  
  224. startdelay    db    7        ; Delay before repeating new char
  225.  
  226. ;    6-minute screen blanking timeout default.
  227.  
  228. BLANKTIME    EQU    (6 * 1092)    ;6 minutes * 1092 ticks per min
  229.  
  230. scrcount    dw    BLANKTIME    ; Time left till screen blanked
  231. screendelay    dw    BLANKTIME    ; "Constant" for refreshing
  232.                     ; scrcount
  233. switches    db SCRMASK AND VIDMASK    ; FASTBUFF off, screen active,
  234.                     ; default screen bl